package com.xkdx.caipiao.presistence.findpsw;

import java.util.HashMap;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.xkdx.caipiao.MainTabActivity;
import com.xkdx.caipiao.R;
import com.xkdx.caipiao.ThreadActivity;
import com.xkdx.caipiao.module.network.AbsModule;

public class ReSetPswActivity extends ThreadActivity {

	ResetPswAction action;
	ResetPswModule module;
	ResetPswPresistence presistence;

	EditText one;
	EditText reset;
	Button next;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.find_psw3_caipiao);
		one = (EditText) findViewById(R.id.one);
		reset = (EditText) findViewById(R.id.two);
		next = (Button) findViewById(R.id.btn_reset_psw);
		next.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				String oneStr = one.getText().toString();
				String twoStr = reset.getText().toString();
				if (oneStr.equals("") || twoStr.equals("")) {
					toast("密码不能为空");
					return;
				}
				if (!oneStr.equals(twoStr)) {
					toast("两次输入密码不一致");
					return;
				}
				startThread();

			}
		});
	}

	@Override
	public void showOnPost(HashMap<String, AbsModule> result) {
		if (result.containsKey("0")) {
			if (module.isSuccess) {
				Intent intent=new Intent(this,ResetResultActivity.class);
				intent.putExtra("isSuccess", true);
				startActivity(intent);
			} else {
				Intent intent=new Intent(this,ResetResultActivity.class);
				intent.putExtra("isSuccess", false);
				startActivity(intent);
			}
		} else {

		}

	}

	@Override
	public void startThread() {
		action = new ResetPswAction(FindPwsActivity.user_name,
				FindPwsCodeActivity.vcode, one.getText().toString());
		module = new ResetPswModule();
		presistence = new ResetPswPresistence(this);
		presistence.setActitons(action);
		presistence.setModule(module);
		presistence.execute();

	}

	@Override
	public void onBackClick(View view) {
		Intent intent = new Intent(this, MainTabActivity.class);
		startActivity(intent);

	}

}
